/*
 * Copyright(C) 2013-2017 AnZhouInc.ALL Rights Reserved.
 *
 * FileName: SwaggerConfig
 * 
 * Description: xxxxx
 *
 * History:
 * 版本号    作者    日期    操作
 * 1.0    ZhouFan 2018/2/11 0011   x
 * ...
 */
package com.fantazy.springswaggerdemo.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

import springfox.documentation.service.ApiInfo;

import springfox.documentation.swagger.web.UiConfiguration;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

/**
 * @author ZhouFan
 * @version 1.0
 * @date 2018/2/11 0011
 * @see
 */
@Configuration
@EnableSwagger2
@EnableWebMvc
@ComponentScan(basePackages = { "com.fantazy.springswaggerdemo" })
public class SwaggerConfig {
    @Bean
    public Docket api() {
        return new Docket( DocumentationType.SWAGGER_2 )
                .groupName( "group name" )
                .select()
                .apis( RequestHandlerSelectors.any() )
                .paths( PathSelectors.any() )
                .build()
                .apiInfo( outApiInfo() );
    }

    private ApiInfo outApiInfo() {

        Contact contact = new Contact( "fantazy", "https://gitee.com/fantazy/", "lazyball@163.com" );

        return new ApiInfo( "ftzy前后端接口",
                "外部接口文档",
                "1.0.0",
                "http://localhost:8080/",
                contact,
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0.html",
                new ArrayList<>() );
       /* return new ApiInfo(
                "ftzy前后端接口", // title 标题
                "外部接口文档", // description 描述 标题下
                "1.2.0", // version
                "http://localhost/", // termsOfService
                "ftzy@gmail.com",
                "Apache 2.0", // licence
                "http://www.apache.org/licenses/LICENSE-2.0.html" // licence url
        );*/

    }

    @Bean
    public UiConfiguration getUiConfig() {
        return new UiConfiguration(
                null,// url,暂不用
                "none",       // docExpansion          => none | list
                "alpha",      // apiSorter             => alpha
                "schema",     // defaultModelRendering => schema
                UiConfiguration.Constants.DEFAULT_SUBMIT_METHODS,
                true,        // enableJsonEditor      => true | false
                true,
                3000L );        // showRequestHeaders    => true | false
    }

}